package com.floreantpos.model;

import java.util.List;

import com.floreantpos.model.base.BaseMenuItem;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class MenuItem extends BaseMenuItem {

  private static final long serialVersionUID = 1L;

  /*[CONSTRUCTOR MARKER BEGIN]*/
  public MenuItem() {
    super();
  }

  /**
   * Constructor for primary key
   */
  public MenuItem(java.lang.Integer id) {
    super(id);
  }

  /**
   * Constructor for required fields
   */
  public MenuItem(
          java.lang.Integer id,
          java.lang.String name,
          java.lang.Double price) {

    super(
            id,
            name,
            price);
  }

  /*[CONSTRUCTOR MARKER END]*/
  public double getPrice(Shift currentShift) {
    List<MenuItemShift> shifts = getShifts();
    double price = super.getPrice();

    if (currentShift == null) {
      return price;
    }
    if (shifts == null || shifts.size() == 0) {
      return price;
    }

    for (MenuItemShift shift : shifts) {
      if (shift.getShift().equals(currentShift)) {
        return shift.getShiftPrice();
      }
    }
    return price;
  }
  
  public String getTaxRateAsString() {
      DecimalFormat decimalFormat = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(new Locale("pt", "BR")));
      String taxRateAsString = "0000";
      if (getTaxRate() >= 10) {
        taxRateAsString = decimalFormat.format(Double.valueOf(getTaxRate())).replace(",", "");
      } else if (getTaxRate() >= 0) {
        taxRateAsString = "0" + decimalFormat.format(Double.valueOf(getTaxRate())).replace(",", "");
      }
      return taxRateAsString;
  }
  
  public String getSituacaoEcfDescription() {
    String situacaoEcfDescription = "<#N/D>";
    
    if (getSituacaoEcf().equals("AL")) {
      situacaoEcfDescription = "%";
    } else if (getSituacaoEcf().equals("FF")) {
      situacaoEcfDescription = "ST";
    } else if (getSituacaoEcf().equals("II")) {
      situacaoEcfDescription = "Isento";
    }
    
    return situacaoEcfDescription;
  }

  @Override
  public String toString() {
    return getName();
  }
}
